<?php
class DynamicAddWarehouseInboundItemFromRequisitionAction extends CAction {
	public function run($id) {
		if (isset($_POST['itemIds']) && is_array($_POST['itemIds'])) {
			$model = $this->getController()->loadModel($id);
			foreach ($_POST['itemIds'] as $reqItemId) {
				$reqItem = MaterialRequisitionItem::model()->findByPk($reqItemId);
				if ($reqItem) {
					$item = new MaterialWarehouseInboundItem();
					$item->materialModelId = $reqItem->materialModelId;
					$item->amount = $reqItem->amount;
					$item->amountStandardUnit = $reqItem->amountStandardUnit;
					$item->unit = $reqItem->unit;
					$item->materialWarehouseInboundId = $id;
					$item->save(false);
				}
			}
		}
		$this->getController()->redirect(array(
				'updateItems',
				'id' => $id
			));
	}
}
